#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# 
#     Question 1
#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#Loading data into R
wage <- read.csv("wage21.csv")

#Summary of key variables
myvars = c("EARNINGS","S", "EXP")
summary(subset(wage, select=myvars))
cor(wage[myvars]) #Sample correlation matrix
pairs(subset(wage, select=myvars)) #Scatter of pairs of variables


#Results
#model1 <- lm(       , data = wage) #OLS estimation


#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# 
#     Question 2
#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#Loading data into R
wage <- read.csv("wage21.csv")

# Summary of key variables
myvars = c("EARNINGS","S", "EXP")
summary(subset(wage, select=myvars))
cor(wage[myvars]) #Sample correlation matrix
pairs(subset(wage, select=myvars)) #Scatter of pairs of variables

#Results
#model2 <- lm(      , data = wage)
#summary(model2)


# Question 2(3)
alpha <- 0.05 #Significance level of the test
df <- df.residual(model2) #Degrees of freedom of RSS
paste("-t_c = ", qt(alpha/2, df, lower.tail = TRUE)) #Lower tail critical value
paste(" t_c = ", qt(alpha/2, df, lower.tail = FALSE)) #Upper tail critical value
se <- summary(model2)$coefficients["EXP",2] #Extracting the estimated standard error
beta_0 <- 0 #Null hypothesis
t_value <- (coef(model2)["EXP"] - beta_0)/se #Calculates the realized value of the test statistic

# Question 2(4)
alpha <- 0.05 #Significance level of the test
df <- df.residual(model2) #Degrees of freedom of RSS
paste(" t_c = ", qt(alpha, df, lower.tail = FALSE)) #Upper tail critical value
se <- summary(model2)$coefficients["EXP",2] #Extracting the estimated standard error
beta_0 <- 0 #Null hypothesis
t_value <- (coef(model2)["EXP"] - beta_0)/se #Calculates the realized value of the test statistic

# Question 2(5)
alpha <- 0.05 #Significance level of the test
df <- df.residual(model2) #Degrees of freedom of RSS
paste("-t_c = ", qt(alpha/2, df, lower.tail = TRUE)) #Lower tail critical value
paste(" t_c = ", qt(alpha/2, df, lower.tail = FALSE)) #Upper tail critical value
se <- summary(model2)$coefficients["S",2] #Extracting the estimated standard error
beta_0 <- 4 #Null hypothesis
t_value <- (coef(model2)["S"] - beta_0)/se #Calculates the realized value of the test statistic


